package com.cctv.order;

import com.cctv.order.message.StreamClient;
import org.junit.Test;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 发送mq消息测试
 *
 * @Author: cctv
 * @Date: 2019/6/11 10:51
 */
@Component
public class MqSender extends OrderApplicationTests {
    @Autowired
    private AmqpTemplate amqpTemplate;

    @Autowired
    private StreamClient streamClient;

    @Test
    public void send() {
        amqpTemplate.convertAndSend("myQueue", "now :" + new Date());
    }

    @Test
    public void sendComputerOrder() {
        amqpTemplate.convertAndSend("myOrder", "computer", "now :" + new Date());
    }

    @Test
    public void process() {
        for (int i = 0; i < 10; i++) {
            String message = i + "now " + new Date();
            streamClient.output().send(MessageBuilder.withPayload(message).build());
        }
    }
}
